package com.easycarebn.request.controller;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.android.volley.Request.Method;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.easycarebn.main.utils.Utils;
import com.easycarebn.request.data.AccountInfoResponse;
import com.easycarebn.request.data.Advisory;
import com.easycarebn.request.data.AppointmentItem;
import com.easycarebn.request.data.AppointmentItemResponse;
import com.easycarebn.request.data.AppointmentListResponse;
import com.easycarebn.request.data.AvatarResponse;
import com.easycarebn.request.data.Booking;
import com.easycarebn.request.data.CityResponse;
import com.easycarebn.request.data.ClinicTypeRespone;
import com.easycarebn.request.data.CommentsResponse;
import com.easycarebn.request.data.ContactInfoResponse;
import com.easycarebn.request.data.DataItem;
import com.easycarebn.request.data.DataItemResponse;
import com.easycarebn.request.data.DoctorDetail;
import com.easycarebn.request.data.DoctorDetailResponse;
import com.easycarebn.request.data.DoctorInfoResponse;
import com.easycarebn.request.data.DoctorScheduleResponse;
import com.easycarebn.request.data.ErrorResponse;
import com.easycarebn.request.data.FavoriteResponse;
import com.easycarebn.request.data.HomeServiceTypeResponse;
import com.easycarebn.request.data.NotificationCountResponse;
import com.easycarebn.request.data.NotificationItem;
import com.easycarebn.request.data.NotificationItemResponse;
import com.easycarebn.request.data.NotificationListResponse;
import com.easycarebn.request.data.Regiter;
import com.easycarebn.request.data.SpecialDetailResponse;
import com.easycarebn.request.data.SpecialityResponse;
import com.easycarebn.request.data.StatusCode;
import com.easycarebn.request.data.SuggestNameResponse;
import com.easycarebn.request.data.UserItem;
import com.easycarebn.request.data.UserProfile;
import com.easycarebn.request.data.UserResponse;
import com.easycarebn.request.data.VersionApp;
import com.easycarebn.service.request.OnRequest;
import com.easycarebn.service.request.RequestManager;
import com.easycarebn.service.volley.toolbox.GsonRequest;
import com.easycarebn.service.volley.toolbox.MultiPartRequest;

public class ServerController {
    private static String TAG = "ServerController";

    public static final String BASE_URL = "http://easycare.vn/api/v1/";
    private static final String GET_LIST_SPECIALITIES = BASE_URL + "home/specialities";
    private static final String GET_LIST_CITIES = BASE_URL + "home/city";
    private static final String GET_LIST_CLINIC_TYPE = BASE_URL + "home/clinictype";
    private static final String GET_LIST_HOME_SERVICE_TYPE = BASE_URL + "home/homeservicetype";
    private static final String GET_LIST_SUGGEST_NAME = BASE_URL + "home/namesuggest?name=%s&type=%d";
    private static final String GET_LIST_SPE_DETAIL = BASE_URL + "home/specdetails?id=";

    private static final String POST_USER_REGISTER = BASE_URL
            + "users/register?email=%s&email_again=%s&password=%s&full_name=%s&sex=%s&year=%s&month=%s&date=%s";
    private static final String USER_LOGIN = BASE_URL + "users/login/patient?email=%s&password=%s&type=patient";
    private static final String GET_USER_LOGOUT = BASE_URL + "users/logout?token=%s&gcm_id=%s";

    private static final String POST_PROFILE_CHANGE_PASS = BASE_URL
            + "profile/changePass?userId=%s&oldPass=%s&newPass=%s&reNewPass=%s&token=%s";
    private static final String POST_PROFILE_LOAD_INFO = BASE_URL + "profile/loadInfo?token=%s";
    private static final String POST_PROFILE_CHANGE_INFO = BASE_URL + "profile/changeInfo?token=%s&full_name=%s&"
            + "email=%s&birth_date=%s&gender=%s&address=%s&email_notification=%s&sms_notification=%s&phone=%s";
    private static final String POST_PROFILE_UPLOAD_AVATAR = BASE_URL + "profile/uploadAvatar?token=%s";

    private static final String GET_SEARCH = BASE_URL + "search?type=%d&numberOfRecords=10&page=%d";
    private static final String GET_SEARCH_DOCTOR_SCHEDULE = BASE_URL + "search/chedulesdoctor?doctorid=%d&date=%s";

    private static final String POST_NOTIFICATION_LIST = BASE_URL + "notification/list?token=%s&page=%d";
    private static final String POST_SEND_CONTACT = BASE_URL + "sendContact?email=%s&name=%s&content=%s";
    private static final String POST_GET_CONTACT = BASE_URL + "getContactInfo";
    private static final String GET_RESET_CODE = BASE_URL + "forgotPass/sendResetCode?phone=%s&force=%d";

    private static final String POST_RIGISTER = BASE_URL + "users/register/patient?phone=%s&full_name=%s";
    private static final String POST_ACTIVE_ACC = BASE_URL + "users/active/activationCode?activationCode=%s";

    private static final String POST_DO_RESET_PASS = BASE_URL + "forgotPass/doResetPass?phone=%s&resetCode=%s";

    private static final String POST_SEND_ADVISORY = BASE_URL
            + "sendAdvisory?id_relationship=%d&name=%s&phone=%s&note=%s&type=%d";

    private static final String POST_NOTIFICATIONS_COUNT = BASE_URL + "notification/countNotification?token=%s";
    private static final String POST_NOTIFICATION_DETAIL = BASE_URL + "notification/detail?token=%s&notification_id=%d";
    private static final String POST_NOTIFICATION_DELETE = BASE_URL + "notification/delete?token=%s&notification_id=%d";
    private static final String POST_NOTIFICATION_SEND_MESSAGE = BASE_URL
            + "notification/sendMessage?token=%s&doctor_id=%d&title=%s&content=%s&reply_for_notification_id=%d";

    private static final String GET_DOCTOR_DETAIL = BASE_URL + "doctor/details?doctorid=%d&type=%d";
    private static final String GET_DOCTOR_COMMENTS = BASE_URL + "doctor/comment?doctorid=%d&page=%d&numberOfRecords=%d";
    private static final String POST_DOCTOR_COMMENT = BASE_URL
            + "patient/CommentDoctor?patient_id=%d&doctor_id=%d&comment=%s&commonsense=%s&facilities=%s&waitingtime=%s&token=%s";

    private static final String ADD_FAVORIRE = BASE_URL + "patient/addFavoriteOfPatient?token=%s&doctor_id=%d";
    private static final String REMOVE_FAVORIRE = BASE_URL + "patient/destroyFavoriteOfPatient?token=%s&doctor_id=%d";
    private static final String GET_FAVORITES = BASE_URL + "patient/favoriteListOfPatient?token=%s&type=%s&pagination=%d";

    private static final String POST_BOOKING = BASE_URL + "bookingPost?";
    private static final String POST_GCM = BASE_URL + "patient/message/gcm/register?token=%s&gcm_regid=%s";

    private static final String GET_PATIENT_APPOINTMENTS = BASE_URL
            + "patient/getAppointments?token=%s&appointmentCode=%s&doctorName=%s&appointmentDate=%s&startDate=%s&endDate=%s&appointmentStatus=%s&numberOfRecords=10&rangeDate=%s&page=%d";
    private static final String CANCEL_PATIENT_APPOINTMENT = BASE_URL + "patient/cancelAppointment?token=%s&id=%d";
    private static final String GET_PATIENT_DETAIL_APPOINTMENT = BASE_URL + "patient/getAppointment?token=%s&id=%d";
    private static final String POST_PATIENT_NOTE_APPOINTMENT = BASE_URL + "patient/addNoteToAppointment?token=%s&id=%d&note=%s";
    private static final String POST_CHECK_UPDATE = BASE_URL + "checkUpgradeApp?type=patient&platform=android";
    private static final String POST_RESEND_CODE_ACTIVE = BASE_URL + "users/get/activationCode?phone=%s";

    private Context mContext;

    private static ServerController mInstance = null;

    private ServerController(Context context) {
        mContext = context;
    }

    public static ServerController getInstance(Context context) {
        if (mInstance == null) {
            mInstance = new ServerController(context);
        }
        return mInstance;
    }

    public void requestcheckUpgradeApp(String email, final OnRequest<VersionApp> req) {

        String url = String.format(POST_CHECK_UPDATE, email);
        System.out.println("URL:\n " + url);
        GsonRequest<VersionApp> request = new GsonRequest<VersionApp>(Method.POST, url, VersionApp.class, null,
                new Listener<VersionApp>() {

                    @Override
                    public void onResponse(VersionApp result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestAddNoteAppointment(String token, int id, String note, final OnRequest<DataItemResponse> req) {
        try {
            note = URLEncoder.encode(note, "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }
        String url = String.format(POST_PATIENT_NOTE_APPOINTMENT, token, id, note);
        System.out.println("URL:\n " + url);
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.POST, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestCancelAppointment(String token, int id, final OnRequest<DataItemResponse> req) {
        String url = String.format(CANCEL_PATIENT_APPOINTMENT, token, id);
        System.out.println("URL:\n " + url);
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.POST, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestRegisterGcm(String token, String gcm_id, final OnRequest<DataItemResponse> req) {
        String url = String.format(POST_GCM, token, gcm_id);
        System.out.println("URL:\n " + url);
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.POST, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestGetAppointment(String token, int id, final OnRequest<AppointmentItem> req) {
        String url = String.format(GET_PATIENT_DETAIL_APPOINTMENT, token, id);
        GsonRequest<AppointmentItemResponse> request = new GsonRequest<AppointmentItemResponse>(Method.GET, url,
                AppointmentItemResponse.class, null, new Listener<AppointmentItemResponse>() {

                    @Override
                    public void onResponse(AppointmentItemResponse result) {
                        req.onSuccess(result.getAppointment());
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestGetListAppointment(String token, String appointmentCode, String doctorName, String appointmentDate,
            String startDate, String endDate, String appointmentStatus, String rangeDate,
            int page, final OnRequest<AppointmentListResponse> req) {
        String url = String.format(GET_PATIENT_APPOINTMENTS, token, appointmentCode, doctorName, appointmentDate, startDate,
                endDate, appointmentStatus, rangeDate, page);
        System.out.println("URL:\n " + url);
        GsonRequest<AppointmentListResponse> request = new GsonRequest<AppointmentListResponse>(Method.POST, url,
                AppointmentListResponse.class, null, new Listener<AppointmentListResponse>() {

                    @Override
                    public void onResponse(AppointmentListResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestBookingForOther(String token, int doctorId, int addressId, String date, String time, String phone,
            String reason, int insurance, int firstVisit, String fullName, String address, String birthday, String gcm_id,
            String device_token, final OnRequest<Booking> req) {
        try {
            reason = URLEncoder.encode(reason, "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }
        try {
            fullName = URLEncoder.encode(fullName, "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }
        try {
            address = URLEncoder.encode(address, "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("doctorId", doctorId + "");
        params.put("addressId", addressId + "");
        params.put("date", date);
        params.put("time", time);
        params.put("phone", phone);
        params.put("firstVisit", firstVisit + "");
        params.put("reason", reason);
        params.put("insurance", insurance + "");
        params.put("fullName", fullName);
        params.put("address", address);
        params.put("token", token);
        params.put("forWhom", "1");
        params.put("birthday", birthday);
        params.put("device_token", device_token);
        params.put("gcm_id", gcm_id);

        requestBooking(params, req);
    }

    public void requestBookingForMe(String token, int doctorId, int addressId, String date, String time, String phone,
            String reason, int insurance, int firstVisit, String gcm_id, String device_token, final OnRequest<Booking> req) {
        try {
            reason = URLEncoder.encode(reason, "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("doctorId", doctorId + "");
        params.put("addressId", addressId + "");
        params.put("date", date);
        params.put("time", time);
        params.put("phone", phone);
        params.put("reason", reason);
        params.put("insurance", insurance + "");
        params.put("token", token);
        params.put("firstVisit", firstVisit + "");
        params.put("device_token", device_token);
        params.put("gcm_id", gcm_id);

        requestBooking(params, req);
    }

    public void requestBookingNotLogin(int doctorId, int addressId, String date, String time, String phone, String reason,
            int insurance, String fullName, String address, String email, int gender, String gcm_id, String device_token,
            final OnRequest<Booking> req) {
        try {
            reason = URLEncoder.encode(reason, "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }
        try {
            fullName = URLEncoder.encode(fullName, "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }
        try {
            address = URLEncoder.encode(address, "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("doctorId", doctorId + "");
        params.put("addressId", addressId + "");
        params.put("date", date);
        params.put("time", time);
        params.put("phone", phone);
        params.put("reason", reason);
        params.put("insurance", insurance + "");
        params.put("fullName", fullName);
        params.put("address", address);
        params.put("email", email);
        params.put("gender", gender + "");
        params.put("device_token", device_token);
        params.put("gcm_id", gcm_id);

        requestBooking(params, req);
    }

    private void requestBooking(final HashMap<String, String> params, final OnRequest<Booking> req) {
        StringBuilder builder = new StringBuilder(POST_BOOKING);
        for (Entry<String, String> entry : params.entrySet()) {
            builder.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
        }
        System.out.println("URL:\n " + builder.toString());
        GsonRequest<Booking> request = new GsonRequest<Booking>(Method.POST, builder.toString(), Booking.class, null,
                new Listener<Booking>() {

                    @Override
                    public void onResponse(Booking result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestGetListFavorites(String token, int type, String nameSearch, int page,
            final OnRequest<DoctorInfoResponse> req) {
        String stype = "DOCTOR";
        if (type == SuggestNameType.CLINIC.getCode()) {
            stype = "CLINIC";
        } else if (type == SuggestNameType.HOME_SERVICE.getCode()) {
            stype = "SERVICE";
        }
        String url = String.format(GET_FAVORITES, token, stype, page);
        if (!TextUtils.isEmpty(nameSearch)) {
            try {
                nameSearch = URLEncoder.encode(nameSearch, "UTF-8");
            } catch (UnsupportedEncodingException e) {
            }
            url += "&nameSearch=" + nameSearch;
        }
        GsonRequest<DoctorInfoResponse> request = new GsonRequest<DoctorInfoResponse>(Method.GET, url, DoctorInfoResponse.class,
                null, new Listener<DoctorInfoResponse>() {

                    @Override
                    public void onResponse(DoctorInfoResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        ErrorResponse er = ErrorResponse.newInStance(err);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestFavorite(final int doctorId, String token, boolean isFavorite, final OnRequest<FavoriteResponse> req) {
        String url = String.format(ADD_FAVORIRE, token, doctorId);
        if (!isFavorite) {
            url = String.format(REMOVE_FAVORIRE, token, doctorId);
        }
        GsonRequest<FavoriteResponse> request = new GsonRequest<FavoriteResponse>(Method.POST, url, FavoriteResponse.class, null,
                new Listener<FavoriteResponse>() {

                    @Override
                    public void onResponse(FavoriteResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestPostDoctorComments(final long patientId, final int doctorId, String token, String comment, int common,
            int facilities, int waitingtime, final OnRequest<DataItemResponse> req) {
        try {
            comment = URLEncoder.encode(comment, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String url = String.format(POST_DOCTOR_COMMENT, patientId, doctorId, comment, common, facilities, waitingtime, token);
        System.out.println("URL:\n " + url);
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.POST, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestGetDoctorComments(final int doctorId, int page, int numberOfRecords, final OnRequest<CommentsResponse> req) {
        String url = String.format(GET_DOCTOR_COMMENTS, doctorId, page, numberOfRecords);

        GsonRequest<CommentsResponse> request = new GsonRequest<CommentsResponse>(Method.GET, url, CommentsResponse.class, null,
                new Listener<CommentsResponse>() {

                    @Override
                    public void onResponse(CommentsResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestGetDoctorDetail(final int doctorId, final int type, final String token, final OnRequest<DoctorDetail> req) {
        String url = String.format(GET_DOCTOR_DETAIL, doctorId, type);
        if (!TextUtils.isEmpty(token)) {
            url += "&token=" + token;
        }
        GsonRequest<DoctorDetailResponse> request = new GsonRequest<DoctorDetailResponse>(Method.GET, url,
                DoctorDetailResponse.class, null, new Listener<DoctorDetailResponse>() {

                    @Override
                    public void onResponse(DoctorDetailResponse result) {
                        if (result == null || result.getItems() == null) {
                            req.onError(0, "No data");
                        } else {
                            req.onSuccess(result.getItems());
                        }
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestSearchDoctorSchedule(final int doctorId, String date, final OnRequest<DoctorScheduleResponse> req) {
        String url = String.format(GET_SEARCH_DOCTOR_SCHEDULE, doctorId, date);

        GsonRequest<DoctorScheduleResponse> request = new GsonRequest<DoctorScheduleResponse>(Method.GET, url,
                DoctorScheduleResponse.class, null, new Listener<DoctorScheduleResponse>() {

                    @Override
                    public void onResponse(DoctorScheduleResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestNotificationSendMessage(String token, int doctorId, String title, String content, File attachFile,
            int reply_for_notification_id, final OnRequest<DataItemResponse> req) {
        try {
            title = URLEncoder.encode(title, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        try {
            content = URLEncoder.encode(content, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String url = String.format(POST_NOTIFICATION_SEND_MESSAGE, token, doctorId, title, content, reply_for_notification_id);
        MultiPartRequest<DataItemResponse> request = new MultiPartRequest<DataItemResponse>(Method.POST, url,
                DataItemResponse.class, new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        if (attachFile != null) {
            request.addFileUpload("attach_file", attachFile);
        }
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestNotificationDelete(final String token, final int notifyId, final OnRequest<DataItemResponse> req) {
        String url = String.format(POST_NOTIFICATION_DELETE, token, notifyId);
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.POST, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestNotificationDetail(final String token, final int notifyId, final OnRequest<NotificationItem> req) {
        String url = String.format(POST_NOTIFICATION_DETAIL, token, notifyId);
        GsonRequest<NotificationItemResponse> request = new GsonRequest<NotificationItemResponse>(Method.POST, url,
                NotificationItemResponse.class, null, new Listener<NotificationItemResponse>() {

                    @Override
                    public void onResponse(NotificationItemResponse result) {
                        req.onSuccess(result.getNotificationContent());
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestNotificationCount(final String token, final OnRequest<Integer> req) {
        String url = String.format(POST_NOTIFICATIONS_COUNT, token);
        GsonRequest<NotificationCountResponse> request = new GsonRequest<NotificationCountResponse>(Method.POST, url,
                NotificationCountResponse.class, null, new Listener<NotificationCountResponse>() {

                    @Override
                    public void onResponse(NotificationCountResponse result) {
                        req.onSuccess(result.getCountNotificaton());
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestSendAdvisory(final int docterId, String name, String phone, String note, int type,
            final OnRequest<Advisory> req) {
        String url = String.format(POST_SEND_ADVISORY, docterId, name, phone, note, type);
        url = url.replace(" ", "%20");
        GsonRequest<Advisory> request = new GsonRequest<Advisory>(Method.POST, url, Advisory.class, null,
                new Listener<Advisory>() {

                    @Override
                    public void onResponse(Advisory result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestSendContact(final String email, String name, String content, final OnRequest<DataItemResponse> req) {
        String url = String.format(POST_SEND_CONTACT, email, name, content);
        url = url.replace(" ", "%20");
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.POST, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestGetContact(final OnRequest<ContactInfoResponse> req) {
        String url = String.format(POST_GET_CONTACT);
        GsonRequest<ContactInfoResponse> request = new GsonRequest<ContactInfoResponse>(Method.POST, url,
                ContactInfoResponse.class, null, new Listener<ContactInfoResponse>() {

                    @Override
                    public void onResponse(ContactInfoResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestNotificationList(final String token, int page, final OnRequest<NotificationListResponse> req) {
        String url = String.format(POST_NOTIFICATION_LIST, token, page);

        GsonRequest<NotificationListResponse> request = new GsonRequest<NotificationListResponse>(Method.POST, url,
                NotificationListResponse.class, null, new Listener<NotificationListResponse>() {

                    @Override
                    public void onResponse(NotificationListResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestUploadAvatar(final String token, final File file, final OnRequest<AvatarResponse> req) {
        String url = String.format(POST_PROFILE_UPLOAD_AVATAR, token);
        MultiPartRequest<AvatarResponse> request = new MultiPartRequest<AvatarResponse>(Method.POST, url, AvatarResponse.class,
                new Listener<AvatarResponse>() {

                    @Override
                    public void onResponse(AvatarResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        request.addFileUpload("avatar", file);
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestSearch(int type, int page, final SearchParamBuilder paramBuilder, final OnRequest<DoctorInfoResponse> req) {
        String url = String.format(GET_SEARCH, type, page);
        if (paramBuilder != null) {
            url += paramBuilder.buildParam();
        }
        GsonRequest<DoctorInfoResponse> request = new GsonRequest<DoctorInfoResponse>(Method.GET, url, DoctorInfoResponse.class,
                null, new Listener<DoctorInfoResponse>() {

                    @Override
                    public void onResponse(DoctorInfoResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        ErrorResponse er = ErrorResponse.newInStance(err);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestProfileChangeProfile(final String token, final String fullname, final String email,
            final String birthdate, final int gender, final String address, final boolean emailnoti,
        String phone,   final OnRequest<DataItemResponse> req) {
        int email_noti = 0;
        int sms_noti = 1;
        if (emailnoti) {
            email_noti = 1;
            sms_noti = 0;
        }
        String url = String.format(POST_PROFILE_CHANGE_INFO, token, fullname, email, birthdate + "", gender, address, email_noti
                + "", sms_noti + "", phone);
        url = url.replace(" ", "%20");
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.POST, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        ErrorResponse er = ErrorResponse.newInStance(err);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestProfileLoadInfo(final String token, final OnRequest<UserProfile> req) {
        String url = String.format(POST_PROFILE_LOAD_INFO, token);
        Log.d(TAG, url);
        GsonRequest<AccountInfoResponse> request = new GsonRequest<AccountInfoResponse>(Method.POST, url,
                AccountInfoResponse.class, null, new Listener<AccountInfoResponse>() {

                    @Override
                    public void onResponse(AccountInfoResponse result) {
                        req.onSuccess(result.getInfo());
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        ErrorResponse er = ErrorResponse.newInStance(err);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestProfileChangePass(final long userId, final String token, final String oldPwd, final String newPwd,
            final OnRequest<DataItemResponse> req) {
        String url = String.format(POST_PROFILE_CHANGE_PASS, userId + "", oldPwd, newPwd, newPwd, token);
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.POST, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        ErrorResponse er = ErrorResponse.newInStance(err);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestUserLogout(final String token,String gcm_id, final OnRequest<DataItemResponse> req) {
        String url = String.format(GET_USER_LOGOUT, token,gcm_id);
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.GET, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        ErrorResponse er = ErrorResponse.newInStance(err);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestUserLogin(final String email, final String password, final OnRequest<UserResponse> req) {
        String url = String.format(USER_LOGIN, email, password);
        GsonRequest<UserResponse> request = new GsonRequest<UserResponse>(Method.GET, url, UserResponse.class, null,
                new Listener<UserResponse>() {

                    @Override
                    public void onResponse(UserResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                    	Log.d("onErrorResponse", err.toString());
                        ErrorResponse er = ErrorResponse.newInStance(err);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestUserRegister(UserItem user, final OnRequest<UserResponse> req) {
        String url = String.format(POST_USER_REGISTER, user.getEmail(), user.getEmailAgain(), user.getPassword(),
                user.getFullname(), user.getSex(), user.getYear(), user.getMonth(), user.getDay());
        url = url.replace(" ", "%20");
        GsonRequest<UserResponse> request = new GsonRequest<UserResponse>(Method.POST, url, UserResponse.class, null,
                new Listener<UserResponse>() {

                    @Override
                    public void onResponse(UserResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        ErrorResponse er = ErrorResponse.newInStance(err);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    /**
     * Get specialist
     */
    public void requestGetSpecialities(final OnRequest<ArrayList<DataItem>> req) {
        ArrayList<DataItem> data = Utils.getRemainData(mContext, "requestGetSpecialities");
        if (!data.isEmpty()) {
            req.onSuccess(data);
            return;
        }
        GsonRequest<SpecialityResponse> request = new GsonRequest<SpecialityResponse>(Method.GET, GET_LIST_SPECIALITIES,
                SpecialityResponse.class, null, new Listener<SpecialityResponse>() {

                    @Override
                    public void onResponse(SpecialityResponse result) {
                        if (result.getCode() != StatusCode.OK) {
                            req.onError(result.getCode(), "");
                            return;
                        }
                        Utils.updateData(mContext, "requestGetSpecialities", result.specialities);
                        req.onSuccess(result.specialities);
                    }

                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        Log.d(TAG, "requestGetSpecialities - onErrorResponse: " + err.getMessage());
                        req.onError(StatusCode.REQUEST_ERROR, err.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    /**
     * Get specialist detail
     */
    public void requestGetSpecialDetail(final OnRequest<ArrayList<DataItem>> req, final int specId) {
        String url = GET_LIST_SPE_DETAIL + specId;
        GsonRequest<SpecialDetailResponse> request = new GsonRequest<SpecialDetailResponse>(Method.GET, url,
                SpecialDetailResponse.class, null, new Listener<SpecialDetailResponse>() {

                    @Override
                    public void onResponse(SpecialDetailResponse result) {
                        Log.d(TAG, "requestGetSpecialities detail - onResponse");
                        if (result.getCode() != StatusCode.OK) {
                            req.onError(result.getCode(), "");
                            return;
                        }
                        req.onSuccess(result.specialitiesdetail);
                    }

                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        Log.d(TAG, "requestGetSpecialities detail - onErrorResponse: " + err.getMessage());
                        req.onError(StatusCode.REQUEST_ERROR, err.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    /**
     * Get cities
     */
    public void requestGetCities(final OnRequest<ArrayList<DataItem>> req) {
        ArrayList<DataItem> data = Utils.getRemainData(mContext, "requestGetCities");
        if (!data.isEmpty()) {
            req.onSuccess(data);
            return;
        }
        GsonRequest<CityResponse> request = new GsonRequest<CityResponse>(Method.GET, GET_LIST_CITIES, CityResponse.class, null,
                new Listener<CityResponse>() {

                    @Override
                    public void onResponse(CityResponse result) {
                        if (result.getCode() != StatusCode.OK) {
                            req.onError(result.getCode(), "");
                            return;
                        }
                        Utils.updateData(mContext, "requestGetCities", result.city);
                        req.onSuccess(result.city);
                    }

                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        Log.d(TAG, "requestGetCities - onErrorResponse: " + err.getMessage());
                        req.onError(StatusCode.REQUEST_ERROR, err.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    /**
     * Get list clinic type
     */
    public void requestGetListClinicType(final OnRequest<ArrayList<DataItem>> req) {
        GsonRequest<ClinicTypeRespone> request = new GsonRequest<ClinicTypeRespone>(Method.GET, GET_LIST_CLINIC_TYPE,
                ClinicTypeRespone.class, null, new Listener<ClinicTypeRespone>() {

                    @Override
                    public void onResponse(ClinicTypeRespone result) {
                        if (result.getCode() != StatusCode.OK) {
                            req.onError(result.getCode(), "");
                            return;
                        }
                        req.onSuccess(result.clinictype);
                    }

                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        Log.d(TAG, "requestGetListClinicType - onErrorResponse: " + err.getMessage());
                        req.onError(StatusCode.REQUEST_ERROR, err.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    /**
     * Get list home service type
     */
    public void requestGetListHomeServiceType(final OnRequest<ArrayList<DataItem>> req) {
        ArrayList<DataItem> data = Utils.getRemainData(mContext, "requestGetListHomeServiceType");
        if (!data.isEmpty()) {
            req.onSuccess(data);
            return;
        }
        GsonRequest<HomeServiceTypeResponse> request = new GsonRequest<HomeServiceTypeResponse>(Method.GET,
                GET_LIST_HOME_SERVICE_TYPE, HomeServiceTypeResponse.class, null, new Listener<HomeServiceTypeResponse>() {

                    @Override
                    public void onResponse(HomeServiceTypeResponse result) {
                        Log.d(TAG, "requestGetCities - onResponse");
                        if (result.getCode() != StatusCode.OK) {
                            req.onError(result.getCode(), "");
                            return;
                        }
                        Utils.updateData(mContext, "requestGetListHomeServiceType", result.homeservice);
                        req.onSuccess(result.homeservice);
                    }

                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        Log.d(TAG, "requestGetListHomeServiceType - onErrorResponse: " + err.getMessage());
                        req.onError(StatusCode.REQUEST_ERROR, err.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    /**
     * Get list suggest name by type
     */
    public void requestGetListSuggestName(final OnRequest<ArrayList<DataItem>> req, String name, final int suggestype) {
        try {
            name = URLEncoder.encode(name, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String url = String.format(GET_LIST_SUGGEST_NAME, name, suggestype);
        GsonRequest<SuggestNameResponse> request = new GsonRequest<SuggestNameResponse>(Method.GET, url,
                SuggestNameResponse.class, null, new Listener<SuggestNameResponse>() {

                    @Override
                    public void onResponse(SuggestNameResponse result) {
                        Log.d(TAG, "requestGetListSuggestName - onResponse");
                        if (result.getCode() != StatusCode.OK) {
                            req.onError(result.getCode(), "");
                            return;
                        }
                        req.onSuccess(result.suggest);
                    }

                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError err) {
                        req.onError(StatusCode.REQUEST_ERROR, err.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestsendResetCode(String email, int foce,final OnRequest<DataItemResponse> req) {
        String url = String.format(GET_RESET_CODE, email,foce);
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.GET, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestRegister(String phone,String full_name, final OnRequest<DataItemResponse> req) {
        String url = String.format(POST_RIGISTER, phone,full_name);
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.POST, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                    	Log.d("VolleyError",error.toString());
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestActiveRegister(String code, final OnRequest<Regiter> req) {
        String url = String.format(POST_ACTIVE_ACC, code);
        GsonRequest<Regiter> request = new GsonRequest<Regiter>(Method.POST, url, Regiter.class, null,
                new Listener<Regiter>() {

                    @Override
                    public void onResponse(Regiter result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                    	Log.d("onErrorResponse",error.toString());
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }
    public void requestdoResendActiveCode(String phone, final OnRequest<DataItemResponse> req) {
        String url = String.format(POST_RESEND_CODE_ACTIVE, phone);
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.POST, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public void requestdoResetPass(String email, String resetCode, final OnRequest<DataItemResponse> req) {
        String url = String.format(POST_DO_RESET_PASS, email, resetCode);
        GsonRequest<DataItemResponse> request = new GsonRequest<DataItemResponse>(Method.POST, url, DataItemResponse.class, null,
                new Listener<DataItemResponse>() {

                    @Override
                    public void onResponse(DataItemResponse result) {
                        req.onSuccess(result);
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ErrorResponse er = ErrorResponse.newInStance(error);
                        req.onError(er.getCode(), er.getMessage());
                    }
                });
        RequestManager.newInstance(mContext).addToRequestQueue(request);
    }

    public static class SearchParamBuilder {
        private HashMap<String, String> mParams;

        public SearchParamBuilder() {
            mParams = new HashMap<String, String>();
        }

        public SearchParamBuilder putCity(int city) {
            if (city > 0) {
                mParams.put("city", city + "");
            }
            return this;
        }

        public SearchParamBuilder putName(String name) {
            if (TextUtils.isEmpty(name)) {
                return this;
            }
            try {
                name = URLEncoder.encode(name, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            mParams.put("name", name);
            return this;
        }

        public SearchParamBuilder putSpecility(int speciality) {
            if (speciality > 0) {
                mParams.put("specialities", speciality + "");
            }
            return this;
        }

        public SearchParamBuilder putDetailSpecility(int detailSpeciality) {
            if (detailSpeciality > 0) {
                mParams.put("detail_specialities", detailSpeciality + "");
            }
            return this;
        }

        public SearchParamBuilder putClinicType(int clinicType) {
            if (clinicType > 0) {
                mParams.put("clinic_type", clinicType + "");
            }
            return this;
        }

        public SearchParamBuilder putServicesType(int servicesType) {
            if (servicesType > 0) {
                mParams.put("services_type", servicesType + "");
            }
            return this;
        }

        public SearchParamBuilder putGeo(double lat, double lng) {
            mParams.put("lat", lat + "");
            mParams.put("lng", lng + "");
            return this;
        }

        public void clear() {
            mParams.clear();
        }

        public String buildParam() {
            StringBuilder builder = new StringBuilder();
            for (Entry<String, String> entry : mParams.entrySet()) {
                builder.append("&").append(entry.getKey()).append("=").append(entry.getValue());
            }
            return builder.toString();
        }
    }
}
